/**
 *
 */
package demo.tellurium.module.gbms

import groovy.lang.MetaClass;
import demo.tellurium.framework.BaseUIModule;

/**
 * @author roger.xu
 *
 */
public class GBMSHomeModule extends BaseUIModule {

    private static final String MODULE_NAME = "GBMSHome";
    public static final String PATH_KEY = "gbms.home.path";

    @Override
    public String getModuleName() {
        return MODULE_NAME;
    }

    public static int ROLE_DEV = 1;

    @Override
    public void defineUi() {
        ui.Container(uid: "GBMSHome") {
            // Sign In
            Button(uid: "SignInButton", clocator: [tag: "input", type: "button", id: "sign_in"])

            // Role
            DOJO_ComboBox(uid: "Role", widgetid: "role")
            Button(uid: "RoleOKButton", clocator: [tag: "input", type: "button", id: "go"])

            // Left Nav
            Div(uid: "LeftNav", clocator: [id: "left-nav"]) {
                UrlLink(uid: "${GBMSLeftNav.RUN_REPORTS.getUid()}", clocator: [tag: "a", text: "Run reports"])
            }
        }
    }

    public void doClickSignInButton() {
        def button = String.format("%s.%s", getModuleName(), "SignInButton");
        click button
        pause 500
        waitForPageToLoad 30000
    }

    public void doSelectRole(int index) {
        console.debug("[ComboBox]", "Role");
        def combobox = String.format("%s.%s", getModuleName(), "Role");
        doSelectComboBoxItem(combobox, index);

        def button = String.format("%s.%s", getModuleName(), "RoleOKButton");
        click button
        pause 500
        waitForPageToLoad 30000
    }

    public void doClickLeftNav(String item) {
        console.debug("[Left Nav]", "go to run reports");

        def link = String.format("%s.%s.%s", getModuleName(), "LeftNav", item);
        click link
        pause 500
        waitForPageToLoad 30000
    }
}
